---
project: deckhouse-web
configVersion: 1
cleanup:
  keepPolicies:
  - references:
      tag: /.*/
  - references:
      branch: /.*/
    imagesPerReference:
      last: 2
  - references:
      branch: main
    imagesPerReference:
      last: 10
gitWorktree:
  forceShallowClone: true
---
# Base Images
{{ $_ := set . "Images" (.Files.Get "../../candi/image_versions.yml" | fromYaml) }}
  {{- range $k, $v := .Images }}
    {{ $baseImagePath := (printf "%s%s" $.Images.REGISTRY_PATH (trimSuffix "/" $v)) }}
    {{- if or (eq $.Env "development") (eq $.Env "module") (eq $.Env "local") }}
      {{ $baseImagePath = trimSuffix "/" $v | splitList "@" | first }}
    {{- end }}
    {{- if ne $k "REGISTRY_PATH" }}
      {{- $_ := set $.Images $k $baseImagePath }}
    {{- end }}
  {{- end }}
---
image: site-tools
from: {{ .Images.BASE_ALPINE }}
shell:
  install: apk add jq curl
---
{{- if and (ne $.Env "development") (ne $.Env "module") (ne $.Env "local") }}
artifact: site-external-artifacts
fromCacheVersion: {{ div .Commit.Date.Unix (mul 60 60) }}v1
fromImage: site-tools
shell:
  install:
    - mkdir -p /data
  setup:
    - echo "Getting data from the API server..."
    - curl --retry-delay 5 --retry 5 {{ env "DOC_API_URL" }}?api-key={{- env "DOC_API_KEY" }} -o /tmp/menus.json
    - |
      jq '.header | if ( ( .en | length) < 1 ) or ( ( .ru | length) < 1 ) then error("Got empty header array!") else ( . | {"topnav": { "en": [{"items": .en}], "ru": [ {"items": .ru}  ]}}) end ' /tmp/menus.json > /data/topnav.json
    - |
      jq '.footer | if ( ( .en | length) < 1 ) or ( ( .ru | length) < 1 ) then error("Got empty footer array!") else ( . | {"columns": . }) end ' /tmp/menus.json > /data/footer.json
    - |
      jq '.copyright | if ( ( .en | length) < 1 ) or ( ( .ru | length) < 1 ) then error("Got empty copyright array!") else . end ' /tmp/menus.json > /data/copyright.json
{{- end }}
---
artifact: web-static
from: {{ .Images.BASE_JEKYLL }}
ansible:
  install:
    - shell: |
        apk add rsync
        gem update --system 3.2.3
        gem install bundler -v 2.4.3
    - name: "Install Dependencies"
      shell: bundle install
      args:
        executable: /bin/bash
        chdir: /srv/jekyll-data/site/
  setup:
    - name: "Build static files"
      shell: |
        export JEKYLL_ENV=production
        mkdir -m 777 -p /app/_site/
        jekyll build -d /app/_site/ --config _config.yml
      args:
        executable: /bin/bash
        chdir: /srv/jekyll-data/site/
git:
- add: /docs/site
  to: /srv/jekyll-data/site
  owner: jekyll
  group: jekyll
  excludePaths:
  - '**/*.sh'
  - LOCAL_DEV.md
  - werf*.yaml
  - docker-compose*.yml
  - .werf
  - .helm
  - backends
  - Makefile
  stageDependencies:
    install: ['Gemfile','Gemfile.lock']
    setup: '**/*'
{{- if and (ne $.Env "development") (ne $.Env "module") (ne $.Env "local") }}
import:
  - artifact: site-external-artifacts
    add: /data/topnav.json
    to: /srv/jekyll-data/site/_data/topnav.json
    before: setup
  - artifact: site-external-artifacts
    add: /data/footer.json
    to: /srv/jekyll-data/site/_data/footer.json
    before: setup
  - artifact: site-external-artifacts
    add: /data/copyright.json
    to: /srv/jekyll-data/site/_data/copyright.json
    before: setup
{{- end }}
---
artifact: web-backend-srv
from: {{ .Images.BASE_GOLANG_16_ALPINE }}
fromCacheVersion: 20210701
ansible:
  install:
    - name: Download dependencies
      shell: |
        go mod tidy
      args:
        executable: /bin/sh
        chdir: /go/src/app
  setup:
    - name: Build apis
      shell: |
        go build -ldflags "-w -s" -v -o /go/src/app/server /go/src/app/cmd/v-router
      args:
        executable: /bin/sh
        chdir: /go/src/app
git:
  - url: https://github.com/flant/web-router.git
    tag: v1.0.14
    add: /
    to: /go/src/app
    stageDependencies:
      install: 'go.mod'
      setup: '**/*'
---
image: web-backend
docker:
  WORKDIR: /app
from: {{ .Images.BASE_ALPINE }}
ansible:
  install:
    - shell: apk add curl jq
import:
  - artifact: web-backend-srv
    add: /go/src/app/server
    to: /app/server
    before: setup
  - artifact: web-static
    add: /app/_site
    to: /app/root
    before: setup
    includePaths:
    - en/includes/
    - ru/includes/
---
image: web-frontend
docker:
  WORKDIR: /app
from: {{ .Images.BASE_NGINX_ALPINE }}
ansible:
  setup:
  - name: "Copy nginx.conf"
    copy:
      content: |
        {{- .Files.Get ".werf/nginx.conf" | nindent 8 }}
      dest: /etc/nginx/nginx.conf
import:
- artifact: web-static
  add: /app/_site
  to: /app
  before: setup
  owner: nginx
  group: nginx
  excludePaths:
  - en/includes/
  - ru/includes/
---
{{ tpl (.Files.Get "werf-docs-builder.inc.yaml") (dict "ctx" . "mode" "default") }}
---
# Build scanner, which fetch modules documentation from list of specified registries
image: registry-modules-watcher-artifact
from: {{ .Images.BASE_GOLANG_20_ALPINE }}
ansible:
  install:
    - name: Download dependencies
      shell: |
        go mod tidy
      args:
        executable: /bin/sh
        chdir: /go/src/app
  setup:
    - name: Build registry-modules-watcher
      shell: |
        go build -ldflags "-w -s" -v -o /go/src/app/registry-modules-watcher /go/src/app/cmd/
      args:
        executable: /bin/sh
        chdir: /go/src/app
git:
  - add: /docs/site/backends/registry-modules-watcher
    to: /go/src/app
    stageDependencies:
      install: 'go.mod'
      setup: '**/*'
---
image: registry-modules-watcher
from: {{ .Images.BASE_ALPINE }}
docker:
  WORKDIR: /app
import:
  - image: registry-modules-watcher-artifact
    add: /go/src/app/registry-modules-watcher
    to: /app/registry-modules-watcher
    before: setup
